local more1__jixi = fk.CreateSkill {
  name = "more1__jixi",
}

Fk:loadTranslationTable{
  ["more1__jixi"] = "击袭",
  [":more1__jixi"] = "当你使用基本牌或锦囊牌时，你可以弃置一名角色区或内至多X张牌；"..
  "若弃置的牌与你使用的牌存在相同：点数，则你获得1枚“袭”；颜色，则你从弃牌堆摸1张牌；花色，则你可以对一名角色造成1点伤害。(X为“袭”的数量+1)",
  ["#more1__jixi-ask"] = "奇袭：选择一名角色你可以弃置其区域内的牌",
  ["@more1__jixi"] = "袭",
  ["#more1__jixi-damage"] = "奇袭：对一名角色造成一点伤害",
  ["$more1__jixi1"] = "后断其援兵，左右包抄，必胜!",
  ["$more1__jixi2"] = "军法如棋局，宁舍子，不错先机!",
}

more1__jixi:addEffect(fk.CardUsing, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(more1__jixi.name) and (data.card.type == Card.TypeBasic or data.card.type == Card.TypeTrick)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
      local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = table.filter(room.alive_players,function(p) 
        return not p:isAllNude()
        end),
      skill_name = more1__jixi.name,
      prompt = "#more1__jixi-ask",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, { tos = to })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local cards = room:askToChooseCards(player, {
      target = to,
      min = 1,
      max = player:getMark("@more1__jixi")+1,
      flag = "hej",
      skill_name = more1__jixi.name,
    })
    room:throwCard(cards, more1__jixi.name, to, player)
    local n = 0 
    local m = 0
    local c = 0  
    for _, p in ipairs(cards) do 
      if data.card.number == Fk:getCardById(p).number then
        n = n + 1
      end
      if data.card.color == Fk:getCardById(p).color then
        m = m + 1 
      end
      if data.card.suit == Fk:getCardById(p).suit then
        c = c + 1
      end 
    end
    if n > 0 then 
      room:addPlayerMark(player,"@more1__jixi",1)
    end
    if m > 0 then 
      local cards = room:getCardsFromPileByRule(".", 1, "discardPile")
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, more1__jixi.name, nil, false, player)
      end
    end
    if c > 0 then 
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = room.alive_players,
        skill_name = more1__jixi.name,
        prompt = "#more1__jixi-damage",
        cancelable = true,
      })
      if #to > 0 then
        room:damage({
          from = player,
          to = to[1],
          damage = 1,
          skillName = more1__jixi.name,
        })
      end
    end
  end,
})

return more1__jixi
